package de.uni.muenster.idw2.data;

import java.util.ArrayList;
import java.util.LinkedList;

import android.os.Parcel;
import android.os.Parcelable;

public class Building implements Parcelable{
	
	private double id;
	private String name;
	private String geopath;
	private String description;
	private ArrayList<String> images = new ArrayList<String>(); // link to image of the building
	
	private LinkedList<Floor> floors = new LinkedList<Floor>();
	
	private static Building building;
	
	
	public Building(Parcel source){
		id = source.readInt();
		name = source.readString();
		geopath = source.readString();
		
		source.readTypedList(floors, Floor.CREATOR);
	}
	
	public static Building getBuilding(){
		if(building == null){
			building = new Building();
		}
		return building;
	}
	
	private Building() {
	}
	
	public void resetBuilding(){
		building = null;
	}

	public double getId() {
		return id;
	}

	public void setId(double id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getGeopath() {
		return geopath;
	}

	public void setGeopath(String geopath) {
		this.geopath = geopath;
	}

	public LinkedList<Floor> getFloors() {
		return floors;
	}

	public void setFloors(LinkedList<Floor> floors) {
		this.floors = floors;
	} 
	
	public void addFloor (Floor floor){
		this.floors.add(floor);
	}
	
	public String toString(){
		String str = "building: ";
		
		str += this.geopath;
		str += " | " + this.name;
		str += " | " + this.id;
		
		for (Floor f: floors){
			str += "  floor: " + f.getId();
			str += " | " + f.getNumber();
			
			for(Room r:f.getRooms()){

				str += "  room: " + r.getId();
				str += " | " + r.getName();
				
				for (Node n : r.getNodes()){
					str += "  node: " + n.getPosition().getX();
					str += " | " + n.getPosition().getY();
					str += " | " + n.getH();
				}
				for (Connection c: r.getConnections()){
					str += "  connection: " + c.getId1();
					str += " | " + c.getId2();
					str += " | " + c.getPosition1().getX();
					str += " | " + c.getPosition1().getY();
					str += " | " + c.getPosition2().getX();
					str += " | " + c.getPosition2().getY();
				}

			}
		}
		
		
		return str;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeDouble(id);
		dest.writeString(name);
		dest.writeString(geopath);
		dest.writeTypedList(floors);
		
	}
	
	public static final Parcelable.Creator CREATOR = new Creator() {

		@Override
		public Building createFromParcel(Parcel source) {
			return new Building(source);
		}

		@Override
		public Building[] newArray(int size) {
			return new Building[size];
		}
	};


	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public ArrayList<String> getImages() {
		return images;
	}

	public void addImage(String image) {
		this.images.add(image);
	}
	
}
